package IOStreamTest.PrintStream;

import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.PrintStream;

/*
printStream:标准输出流，默认输出到控制台
 */
public class PrintStreamTest1 {
    public static void main(String[] args) {
        //联合起来写
        System.out.println("你好");

        //分开写
        PrintStream ps = System.out;
        ps.println("你好我是java");
        //标准输出流不需要手动close()关闭
        //修改输出方向，讲内容输出到log文件中
        PrintStream pr = null;
        try {
            pr = new PrintStream(new FileOutputStream("D:\\myFile3.txt"));
            //改变输出流方向 setOut
            System.setOut(pr);

            pr.println("你好，我是张三");
            pr.println("\njava");
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        }

    }
}
